#ifndef FOUNDATION_PROTOCOL_XCOMNODE_H
#define FOUNDATION_PROTOCOL_XCOMNODE_H
#include <map>
#include <memory>
#include "dbms.pb.h"
#include <express.h>

namespace protocol {
typedef struct {
	std::string flow;
	libxcom::XExpress resultExpr;
	std::unordered_map<std::string, libxcom::OpValue> vars;
	std::string format;
} FuncParam_t;

typedef struct {
	std::string call;
	libxcom::XExpress expr;
} Process_t;

typedef struct {
	std::vector<Process_t> procList;
} Flow_t;

class XComNode {
public:
	void SetName(const std::string &name);

	void AddFlow(const std::string &flow);
	void AddFlowExpr(const std::string &flow, const std::string &op,
		const std::string &expr);
	void AddFuncPointVar(const std::string &func, const std::string &var,
		const std::string &expr);

	void SetTemplate(const std::string &temp);
	void SetId(const std::string &id);
	std::string GetFormat(const std::string &funcId);

	const std::string &GetName() const;
	const std::string &GetId() const;
	const std::string &GetTemplate() const;
	const Flow_t GetFlow(const std::string &key) const;
	bool HasFuncId(const std::string &id);
	const FuncParam_t &GetFuncParam(const std::string &funcId) const;

private:
	libxcom::OpValue ExprToValue(const std::string &expr);
	std::shared_ptr<libxcom::Express> WrapExpress(const std::string &str);

private:
	std::string id_;
	std::string name_;
	std::string template_;
	std::unordered_map<std::string, Flow_t> mapFlow_;
	std::unordered_map<std::string, FuncParam_t> funcPoints_;
};
} // namespace protocol
#endif // FOUNDATION_PROTOCOL_XCOMNODE_H